<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Overview map | Sample | ArcGIS API for JavaScript 4.17</title>
    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
        z-index: -1;
      }

      #overviewDiv {
        position: absolute;
        top: 12px;
        right: 12px;
        width: 300px;
        height: 200px;
        border: 1px solid black;
        z-index: 1;
        overflow: hidden;
      }

      #extentDiv {
        background-color: rgba(0, 0, 0, 0.5);
        position: absolute;
        z-index: 2;
      }
    </style>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.17/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.17/"></script>

    <script>
      require([
        "esri/Map",
        "esri/views/SceneView",
        "esri/views/MapView",
        "esri/Graphic",
        "esri/core/watchUtils"
      ], function (Map, SceneView, MapView, Graphic, watchUtils) {
        // Create a Map with a basemap, to be used with in the main view
        var mainMap = new Map({
          basemap: "hybrid",
          ground: "world-elevation"
        });

        // Create another Map, to be used in the overview "view"
        var overviewMap = new Map({
          basemap: "topo-vector"
        });

        // Create the SceneView
        var mainView = new SceneView({
          container: "viewDiv",
          map: mainMap,
          camera: {
            position: {
              spatialReference: {
                latestWkid: 3857,
                wkid: 102100
              },
              x: 925151,
              y: 5956309,
              z: 3871
            },
            heading: 203,
            tilt: 72
          }
        });

        // Create the MapView for overview map
        var mapView = new MapView({
          container: "overviewDiv",
          map: overviewMap,
          constraints: {
            rotationEnabled: false
          }
        });

        // Remove the default widgets
        mapView.ui.components = [];

        mapView.when(function () {
          mainView.when(function () {
            setup();
          });
        });

        function setup() {
          const extent3Dgraphic = new Graphic({
            geometry: null,
            symbol: {
              type: "simple-fill",
              color: [0, 0, 0, 0.5],
              outline: null
            }
          });
          mapView.graphics.add(extent3Dgraphic);

          watchUtils.init(mainView, "extent", function (extent) {
            // Sync the overview map location
            // whenever the 3d view is stationary
            if (mainView.stationary) {
              mapView
                .goTo({
                  center: mainView.center,
                  scale:
                    mainView.scale *
                    2 *
                    Math.max(
                      mainView.width / mapView.width,
                      mainView.height / mapView.height
                    )
                })
                .catch(function (error) {
                  // ignore goto-interrupted errors
                  if (error.name != "view:goto-interrupted") {
                    console.error(error);
                  }
                });
            }

            extent3Dgraphic.geometry = extent;
          });
        }
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="overviewDiv"><div id="extentDiv"></div></div>
  </body>
</html>
